package com.lagou.edu.service.impl;

import com.lagou.edu.dao.HomeworkDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("homeworkService")
@Transactional
public class HomeworkServiceImpl implements HomeworkService {
    @Autowired
    @Qualifier("homeworkDao")
    private HomeworkDao homeworkDao;
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = homeworkDao.queryByCardNo(fromCardNo);
        Account to = homeworkDao.queryByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        homeworkDao.updateByCardNo(to);
        //int c = 1/0;
        homeworkDao.updateByCardNo(from);
    }
}
